package com.gen.generator.util;

import javax.swing.*;
import java.awt.*;
import java.io.PrintWriter;
import java.io.StringWriter;

public class ErrorUtil {

    public static void showError(Exception ex, Component component) {
        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw));
        JTextArea textArea = new JTextArea(sw.toString());
        textArea.setEditable(false);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        // 使用 JBScrollPane 替代 JScrollPane
        com.intellij.ui.components.JBScrollPane scrollPane = new com.intellij.ui.components.JBScrollPane(textArea);
        scrollPane.setPreferredSize(new Dimension(600, 400));
        JOptionPane.showMessageDialog(component, scrollPane,"连接失败: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
    }
}
